package course_platform;

import java.util.ArrayList;
import java.util.List;

public class Student extends Person {
    private List<Course> courses; // 选修课程列表

    public Student(String id, String name, String gender) {
        super(id, name, gender); // 调用父类构造方法
        this.courses = new ArrayList<>();
    }

    public List<Course> getCourses() {
        return courses;
    }

    public void addCourse(Course course) {
        if (!courses.contains(course)) {
            courses.add(course);
            course.addStudent(this);
        }
    }

    public void removeCourse(Course course) {
        courses.remove(course);
    }

    public boolean isEnrolledInCourse(Course course) {
        return courses.contains(course);
    }

    @Override
    public void printSchedule() {
        if (courses.isEmpty()) {
            System.out.println("课表：未选任何课程。\n");
        } else {
            System.out.println("课表：\n");
            for (Course course : courses) {
                System.out.println("课程编号:" + course.getCode() + ", 课程名称:" + course.getCourseName() +
                        ", 上课地点:" + course.getLocation() + ", 时间:" + course.getTime());
                for (Teacher teacher : course.getTeachers()) {
                    System.out.println("授课教师:" + teacher.getName() + ", 性别：" + teacher.getGender());
                }
            }
            System.out.println();
        }
    }
}